import axios from 'axios'
import list from '@/utils/list'
// import get from '@/api/user'

const request = axios.create({
  baseURL: 'http://192.168.32.51:3000/'
})

// 请求拦截器
request.interceptors.request.use((config) => {
  // Object.keys(list).some(v =>
  //   v === config.url.substr(1)
  // )
  if (config.method === 'post') {
    config.data = {
      ...list[config.url.substr(1)], ...config.data
    }
  }
  return config
}, (err) => {
  return Promise.reject(err)
})
// 响应拦截器
request.interceptors.response.use((res) => {
  // var url = res.config.url.match(/3000\/([a-z]*)/)[1]
  // console.log(url)
  // console.log(window.document.location.href)
  res.total = res.data.length
  return res
}, (err) => {
  return Promise.reject(err)
})

export default request
